package com.yunquan.ohana.ui.calendar.profiles.list

import androidx.core.graphics.toColorInt
import androidx.databinding.ObservableField
import com.yunquan.ohana.base.binding.command.BindingAction
import com.yunquan.ohana.base.binding.command.BindingCommand
import com.yunquan.ohana.base.ui.ItemViewModel
import com.yunquan.ohana.entity.RoleEntity

class ProfilesListItemViewModel(viewModel: ProfilesListViewModel) : ItemViewModel<ProfilesListViewModel>(viewModel) {
    var data: RoleEntity? = null
    val prefix = ObservableField<String>()
    val name = ObservableField<String>()
    val account = ObservableField<String>()
    val color = ObservableField<Int>()

    constructor(viewModel: ProfilesListViewModel, data: RoleEntity) : this(viewModel) {
        this.data = data
        this.prefix.set(data.name?.first().toString())
        this.name.set(data.name)
        this.account.set(data.account)
        this.color.set(data.getColorData().inner.toColorInt())
    }

    val onItemClick = BindingCommand<Any>(object : BindingAction{
        override fun call() {
            viewModel.onEditProfiles(data!!)
        }
    })
}